package BBDD;

import java.sql.*;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;

import DAO.AlumnoDAO;
import DAO.NotaAlumnoDAO;
import DAO.NotaParcialAlumnoDAO;
import DAO.ProfesorDAO;

public class ManageNotasParcialAlumno {

	private Connection conn;
	private Statement pstmt;
	private ResultSet rs;
	private String query;
	private ManageDB abreConn;
	private Vector<NotaParcialAlumnoDAO> notaParcialAlumno=new Vector<NotaParcialAlumnoDAO>();

	public ManageNotasParcialAlumno() {
		abreConn = new ManageDB();
		conn = abreConn.getConnection();
	
		abreConn.OpenDB();
	}

	public void loadNotaParcialAlumno(String query) {
		this.query = query;
		conn = abreConn.getConnection();
		
		try {
			pstmt = conn.createStatement();
			rs = pstmt.executeQuery(query);		
			
			while (rs.next()) {
				int idNotaParcialAlumno = rs.getInt(1);
				int idTipoNotaParcial= rs.getInt(2);
				int idGrupo = rs.getInt(3);
				int idModulo = rs.getInt(4);
				int idAlumno = rs.getInt(5);
				int idProfesor = rs.getInt(6);
				int evaluacionNotaAlumno = rs.getInt(6);
				setNotaParcialAlumno(new NotaParcialAlumnoDAO(idNotaParcialAlumno,idTipoNotaParcial, idGrupo, idModulo,
						idAlumno, idProfesor, evaluacionNotaAlumno));


			}

		} catch (SQLException ex) {
			Logger.getLogger(ManageNotasParcialAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {
			try {
				rs.close();
				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
	}

	public void updateNotaParcialAlumno(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageNotasParcialAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public void deleteNotaParcialAlumno(String query) {
		this.query = query;

		conn = abreConn.getConnection();

		try {

			pstmt = conn.prepareStatement(query);
			pstmt.execute(query);
		} catch (SQLException ex) {
			Logger.getLogger(ManageNotasParcialAlumno.class.getName()).log(Level.SEVERE,
					null, ex);
		} finally {

			try {

				pstmt.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

	public String getOldQuery() {
		return query;
	}

	public Vector<NotaParcialAlumnoDAO> getNotaParcialAlumno() {
		return notaParcialAlumno;
	}

	public void setNotaParcialAlumno(NotaParcialAlumnoDAO notaParcialAlumno) {
		this.notaParcialAlumno.add(notaParcialAlumno);
	}

}
